﻿// ===============================================================================
// For .NET 2.0
//
// File :         DangerTrack_DangerTrack.cs
// Date :         2010-04-23
// Decription :   危险源
// Author:        fisher
// 其他信息:      危险源信息表
//                EnterpriseID   企业ID
// ===============================================================================
// 版本变更记录
// Version Decription
//   1.0  	
// ===============================================================================
// 公司名称:Elota
// ===============================================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Elota.DAO;
using Elota.SCAQGL.BLL;
using Elota.SCAQGL.Models;
using Elota.SCAQGL.CommandTools;
using System.Collections.Generic;
using Elota.SCAQGL.DAL;
public partial class DangerTrack_AidTarget : BasicPage
{
    /// <summary>
    /// 危险源 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// 

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //ShowMessage(this, Request["AgvyId"]+"1");
            //this.ddlPageSize.SelectedIndex = 0;
            //this.gvAidTarget.PageIndex = 0;
            //this.btnDelete.Attributes.Add("onclick", GetDeleteJsString("真的要删除吗"));
           // this.BindGridView();
           //this.BindDropDownList();
            //if (!CurrentUser.UserType.Equals(1))
            //{
                //this.lbtnAdd.Visible = false;
               // this.lbtnAdd.Attributes.Add("onclick", "javascript:alert('对不起只有企业用户才能编辑信息');return false;");
                
           // }
        }
    }

    ////保存选择的机构类型
    //private string riskState;

    //public string RiskState
    //{
    //    get { return riskState; }
    //    set { riskState = value; }
    //}


    ////保存机构成员
    //private string dangerLevel;

    //public string DangerLevel
    //{
    //    get { return dangerLevel; }
    //    set { dangerLevel = value; }
    //}

    /// <summary>
    /// 绑定GridView
    /// </summary>
    protected void BindGridView()
    {
        //IList<AidTarget> models = AidTargetDAL.Instance.GetModels(GetSearchWhere());
        //this.gvAidTarget.DataSource = models;
       // this.gvAidTarget.DataBind();

        //this.lbCurrentPageInfo.Text= GetCurrentPageInfo(models.Count, this.gvAidTarget.PageIndex, this.gvAidTarget.PageCount);
       // divNone.Visible = models.Count.Equals(0);
       // divPage.Visible = !models.Count.Equals(0);
       // this.gvAidTarget.Columns[0].Visible = CurrentUser.UserType.Equals(1);
        //ViewState["style"] = models.Equals(0) && CurrentUser.UserType.Equals(1) ? "display:none" : "display:inline";
        //if (!CurrentUser.UserType.Equals(1)) ViewState["style"] = "display:none";
    }
    /// <summary>
    /// 获取查询条件
    /// </summary>
    protected string GetSearchWhere()
    {
        string strWhere = " Where 1 = 1  " ;
        if (Request["DisID"] != null)
            strWhere += string.Format(" AND DisposaPlanId ='{0}' ", Request["DisID"].ToString());
        
        return strWhere;

    }
    /// <summary>
    /// 页面改变
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void OnPageChange(object sender, EventArgs e)
    {
        //LinkButton lbtn = sender as LinkButton;
        //switch (lbtn.CommandName)
        //{
        //    case "OnFirstPage": //首页
        //        this.gvAidTarget.PageIndex = 0;
        //        this.BindGridView();
        //        break;
        //    case "OnNextPage"://下一页
        //        if (this.gvAidTarget.PageIndex.Equals(this.gvAidTarget.PageCount - 1))
        //            this.gvAidTarget.PageIndex = this.gvAidTarget.PageCount - 1;
        //        else
        //            this.gvAidTarget.PageIndex += 1;
        //        this.BindGridView();
        //        break;
        //    case "OnPrevPage"://上一页
        //        if (this.gvAidTarget.PageIndex.Equals(0))
        //            this.gvAidTarget.PageIndex = 0;
        //        else
        //            this.gvAidTarget.PageIndex -= 1;
        //        this.BindGridView();
        //        break;
        //    case "OnLastPage"://最后一页
        //        this.gvAidTarget.PageIndex = this.gvAidTarget.PageCount - 1;
        //        this.BindGridView();
        //        break;
       // }
    }
    /// <summary>
    /// 跳转到指定页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GoPage(object sender, EventArgs e)
    {
        //Int32 pageIndex = this.gvAidTarget.PageIndex;
        //Boolean result = Int32.TryParse(tbPageIndex.Text, out pageIndex);
        //if (result)//转换成功则进行判断
        //{
        //    if (pageIndex > 0 && pageIndex <= this.gvAidTarget.PageCount)
        //    {
        //        this.gvAidTarget.PageIndex = pageIndex - 1;
        //        this.BindGridView();
        //    }
        //    else
        //        ShowMessage(this, "页码输入不正确");
        //}
        //else
        //    ShowMessage(this, "页码输入不正确");
    }
    /// <summary>
    /// 页面尺寸改变时
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void OnPageSizeChanged(object sender, EventArgs e)
    {
        //this.gvAidTarget.PageSize = Int32.Parse(this.ddlPageSize.SelectedValue);
        //this.gvAidTarget.PageIndex = 0;
        //this.BindGridView();
    }

    protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        //string strUrl = "";
        switch (e.CommandName)
        {
            case "OnUpdate":
                this.OnUpdate(e.CommandArgument.ToString());
                break;
            case "OnDelete":
                this.OnDelete(e.CommandArgument.ToString());
                break;
            case"OnRoteView":
                this.OnRoteView(e.CommandArgument.ToString());
                break;
            case"OnNotesView":
                this.OnNotesView(e.CommandArgument.ToString());
                break;

        }
    }

    protected void OnRoteView(string key)
    {
        string strUrl = "../Dialog/BigTextView.aspx?TableName={0}&KeyName={1}&KeyVal={2}&FieldName={3}&BackUrl={4}&ModuleName={5}";
        string strBackUrl = string.Format("../DangerTrack/AidTarget.aspx?DisID={0}", key);
        strUrl = string.Format(strUrl, "AidTarget", "RescueTargetId", key, "rote", strBackUrl, "详细内容");
        Response.Redirect(strUrl);
    }
    protected void OnNotesView(string key)
    {
        string strUrl = "../Dialog/BigTextView.aspx?TableName={0}&KeyName={1}&KeyVal={2}&FieldName={3}&BackUrl={4}&ModuleName={5}";
        string strBackUrl = string.Format("../DangerTrack/AidTarget.aspx?DisID={0}", key);
        strUrl = string.Format(strUrl, "AidTarget", "RescueTargetId", key, "notes", strBackUrl, "详细内容");
        Response.Redirect(strUrl);
    }
    /// <summary>
    /// 修改查看
    /// </summary>
    /// <param name="iKey"></param>
    protected void OnUpdate(string sKey)
    {
        Session["AgvyId"] = Request["AgvyId"];
        Response.Redirect(string.Format("AidTargetEdit.aspx?RescueTargetId={0}&DisID={1}&AgvyId={2}&SSerialID={3}",sKey, Request["DisID"], Request["AgvyId"], Request["SSerialID"]));
    }
    /// <summary>
    /// 应急预案
    /// </summary>
    /// <param name="iKey"></param>
    protected void OnDelete(string sKey)
    {
        //AidTarget model = AidTargetBLL.Instance.GetModelByKey(sKey);
        //model.RescueTargetId = ConvertToInt(sKey);
        //if (AidTargetBLL.Instance.Del(model))
        //{
        //    DisposalPlan modeldis = DisposalPlanBLL.Instance.GetModelByKey(Request["DisID"].ToString());
        //    ShowMessage(this, modeldis.NeedlMonmey.ToString());
        //    modeldis.NeedlMonmey = modeldis.NeedlMonmey - model.NeedlMonmey;
        //    modeldis.NeedPeople = modeldis.NeedPeople - model.NeedPeople;
        //    if (modeldis.NeedlMonmey < 0)
        //    {
        //        modeldis.NeedlMonmey = 0;
        //    }
        //    if (modeldis.NeedPeople < 0)
        //    {
        //        modeldis.NeedPeople = 0;
        //    }
        //    DisposalPlanDAL.Instance.Update(modeldis);
        //    this.BindGridView();
        //}
    }
    /// <summary>
    /// 删除所有
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void OnDeleteAll(object sender, EventArgs e)
    {

        //foreach (GridViewRow r in this.gvAidTarget.Rows)
        //{
        //    CheckBox cb = r.FindControl("cbxSelect") as CheckBox;
        //    Label lab = r.FindControl("labPageID") as Label;
        //    if (cb != null && lab != null && cb.Checked)
        //    {
        //        AidTarget model = new AidTarget();
        //        model.RescueTargetId = ConvertToInt(lab.Text);
        //        AidTargetDAL.Instance.Delete(model);
        //    }
        //}
        //this.BindGridView();
    }
   
    /// <summary>
    /// 新增应急预案
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnAdd_Click1(object sender, EventArgs e)
    {
        Session["AgvyId"] = Request["AgvyId"];
        Response.Redirect(string.Format("AidTargetEdit.aspx?DisID={0}&AgvyId={1}&SSerialID={2}", Request["DisID"],Request["AgvyId"],Request["SSerialID"]));

    }
    protected void lbtnBack_Click(object sender, EventArgs e)
    {
        string BackUrl = string.Format("../DangerTrack/DisposalPlan.aspx?SSerialID={0}", Request["SSerialID"]);
        Response.Redirect(BackUrl);
    }
    protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        BindGridView();
    }


    
    protected string GetMapPath()
    {
        //string Id = Request["SSerialID"].ToString();
        //return string.Format("<a href='../DangerTrack/DangerTrack.aspx?SerialID={0}'>危险源跟踪</a> >>  应急预案 ", Id);
        return "隐患排查治理>>应急预案>>救助目标";
    }



    //  以下注释请暂时不要删除!

    //protected void BindDropDownList()
    //{
    //    //风险状态
    //    this.ddlRiskState.DataSource = SchemaCode.Instance.GetHazardType();
    //    this.ddlRiskState.DataValueField = "CodeID";
    //    this.ddlRiskState.DataTextField = "CodeName";
    //    this.ddlRiskState.DataBind();

    //    //危险等级
    //    this.ddlDangerLevel.DataSource = SchemaCode.Instance.GetDangerLevel();
    //    this.ddlDangerLevel.DataValueField = "CodeID";
    //    this.ddlDangerLevel.DataTextField = "CodeName";
    //    this.ddlDangerLevel.DataBind();
    //}
    //protected void SetDangerLevel()
    //{
    //    //this.ddlDangerCode.SelectedValue = SchemaCode.Instance.GeDBSchemaByCodeID(model.DangerCode);
    //    if (this.ddlRiskState.SelectedValue.Equals("1201"))//如果是危险源  
    //    {
    //        this.ddlDangerLevel.DataSource = SchemaCode.Instance.GetDangerLevel();
    //        this.lblShowdDngerorAccident.Text = "危险源等级"; //动态改变现实是哪个危险源的等级
    //    }
    //    if (this.ddlRiskState.SelectedValue.Equals("1202"))//如果是事故   
    //    {
    //        this.ddlDangerLevel.DataSource = SchemaCode.Instance.GetAccidentLevel();//事故等级
    //        this.lblShowdDngerorAccident.Text = "事故等级";
    //    }

    //    if (this.ddlRiskState.SelectedValue.Equals("1202") || this.ddlRiskState.SelectedValue.Equals("1203"))//如果是事故 
    //    {
    //        this.ddlDangerLevel.DataSource = SchemaCode.Instance.GetAccidentLevel();//事故等级
    //        this.lblShowdDngerorAccident.Text = "事故等级";
    //    }

    //    if (this.ddlRiskState.SelectedValue.Equals("1204") || this.ddlRiskState.SelectedValue.Equals("1205"))//如果是事故 
    //    {
    //        this.ddlDangerLevel.DataSource = SchemaCode.Instance.GetHiddenDangerLevel();
    //        this.lblShowdDngerorAccident.Text = "事故等级";
    //    }

    //    this.ddlDangerLevel.DataValueField = "CodeID";
    //    this.ddlDangerLevel.DataTextField = "CodeName";
    //    this.ddlDangerLevel.DataBind();


    //}


    //protected void ddlRiskState_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    SetDangerLevel();//设置事故等级
    //    if (this.ddlRiskState.SelectedValue.Equals("1201"))
    //    {
    //        this.RiskState = "1201";
    //        this.BindGridView();
    //    }
    //    if (this.ddlRiskState.SelectedValue.Equals("1202"))
    //    {
    //        this.RiskState = "1202";
    //        this.BindGridView();
    //    }
    //    if (this.ddlRiskState.SelectedValue.Equals("1203"))
    //    {
    //        this.RiskState = "1203";
    //        this.BindGridView();
    //    }
    //    if (this.ddlRiskState.SelectedValue.Equals("1204"))
    //    {
    //        this.RiskState = "1204";
    //        this.BindGridView();
    //    }
    //    if (this.ddlRiskState.SelectedValue.Equals("1205"))
    //    {
    //        this.RiskState = "1205";
    //        this.BindGridView();
    //    }
    //}

    ////对事故等级进行处理 筛选数据
    //protected void ddlDangerLevel_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (this.ddlDangerLevel.SelectedValue.Equals("1301"))
    //    {
    //        this.RiskState = "1201";
    //        this.DangerLevel = "1301";
    //        this.BindGridView();
    //    }
    //    if (this.ddlDangerLevel.SelectedValue.Equals("1302"))
    //    {
    //        this.RiskState = "1201";
    //        this.DangerLevel = "1302";
    //        this.BindGridView();
    //    }
    //    if (this.ddlDangerLevel.SelectedValue.Equals("1501"))
    //    {
    //        this.RiskState = "1202";
    //        this.DangerLevel = "1501";
    //        this.BindGridView();
    //    }
    //    if (this.ddlDangerLevel.SelectedValue.Equals("1502"))
    //    {
    //        this.RiskState = "1202";
    //        this.DangerLevel = "1502";
    //        this.BindGridView();
    //    }
    //    if (this.ddlDangerLevel.SelectedValue.Equals("1503"))
    //    {
    //        this.RiskState = "1202";
    //        this.DangerLevel = "1503";
    //        this.BindGridView();
    //    }
    //    if (this.ddlDangerLevel.SelectedValue.Equals("1504"))
    //    {
    //        this.RiskState = "1202";
    //        this.DangerLevel = "1504";
    //        this.BindGridView();
    //    }
    //}
   
}
